package cn.edu.hgu.action;

import java.util.List;

import javax.annotation.Resource;

import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ModelDriven;

import cn.edu.hgu.bean.AdminInfo;
import cn.edu.hgu.bean.AdminRoleInfo;
import cn.edu.hgu.service.AdminService;
import cn.edu.hgu.util.FastJsonUtil;
import cn.edu.hgu.util.PageResult;

public class AdminAction extends BaseAction implements ModelDriven<AdminInfo> {

	private static final long serialVersionUID = 1L;
	private AdminInfo adminInfo;
	@Resource(name="adminService")
	private AdminService adminService;
	private PageResult<AdminInfo> pageResult = new PageResult<AdminInfo>();

	public AdminInfo getModel() {
		if(adminInfo == null) {
			adminInfo = new AdminInfo();
		}
		return adminInfo;
	}
	
	public void setAdminService(AdminService adminService) {
		this.adminService = adminService;
	}

	public PageResult<AdminInfo> getPageResult() {
		return pageResult;
	}
	
	public String account_list() {
		adminService.findByPage(null, pageResult, null);
		return "account_list";
	}
	
	public String findAdminRole() {
		List<AdminRoleInfo> adminRoleList = adminService.findAdminRole();
		String jsonString = FastJsonUtil.toJSONString(adminRoleList);
		FastJsonUtil.write_json(ServletActionContext.getResponse(), jsonString);
		return null;
	}
	
}
